package com.app.utils;

import android.graphics.Bitmap;
import android.text.TextUtils;
import android.widget.ImageView;

import com.app.application.MyApplication;
import com.lidroid.xutils.BitmapUtils;
import com.lidroid.xutils.bitmap.BitmapCommonUtils;

/**
 * Created by wxd on 2016/6/16.
 *
 * xUtil 通用获取图片
 */
public class BitmapLoadUtil {

    public static BitmapUtils bitmapUtils = BitmapHelp.getBitmapUtils(MyApplication.getInstance(),SdLocal.getTempFolder(MyApplication.getInstance()));

    public static void displayImage(int resIconDefaultId,String imageUrl,ImageView imageView)
    {
        if(TextUtils.isEmpty(imageUrl))
        {
            imageView.setImageResource(resIconDefaultId);
            return;
        }
        bitmapUtils.configDefaultLoadingImage(resIconDefaultId);
        bitmapUtils.configDefaultLoadFailedImage(resIconDefaultId);
        bitmapUtils.configDefaultBitmapConfig(Bitmap.Config.ARGB_8888);
        bitmapUtils.configDefaultBitmapMaxSize(BitmapCommonUtils.getScreenSize(MyApplication.getInstance()).scaleDown(3));
        bitmapUtils.display(imageView, imageUrl);
    }

    public static void clearAllCache()
    {
        bitmapUtils.clearMemoryCache();
        bitmapUtils.clearCache();
        bitmapUtils.clearDiskCache();
    }
}
